package com.custom.base.base

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity

/**
 * 适配 AutoLayout
 */
abstract class AutoLayoutActivity : AppCompatActivity() {
    override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
        var view: View? = null
        if (name == LAYOUT_FRAMELAYOUT) {
            view = FrameLayout(context, attrs)
        }

        if (name == LAYOUT_LINEARLAYOUT) {
            view = LinearLayout(context, attrs)
        }

        if (name == LAYOUT_RELATIVELAYOUT) {
            view = RelativeLayout(context, attrs)
        }

        return view ?: super.onCreateView(name, context, attrs)

    }

    companion object {
        private val LAYOUT_LINEARLAYOUT = "LinearLayout"
        private val LAYOUT_FRAMELAYOUT = "FrameLayout"
        private val LAYOUT_RELATIVELAYOUT = "RelativeLayout"
    }
}
